package com.chaofan.sell.entity;

import com.chaofan.sell.enums.ProductStatus;
import com.chaofan.sell.utils.EnumUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Entity;
import javax.persistence.Id;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 商品
 *
 * @author: Fairy
 * @date: 2021/9/6
 */
@Entity
@Data
@NoArgsConstructor
@DynamicUpdate
public class ProductInfo implements Serializable {

    private static final long serialVersionUID = -8928126845544526120L;
    /**
     * 商品id
     */
    @Id
    private String productId;

    /**
     * 商品名
     */
    private String productName;

    /**
     * 商品单价
     */
    private BigDecimal productPrice;

    /**
     * 商品库存
     */
    private Integer productStock;

    /**
     * 商品描述
     */
    private String productDescription;

    /**
     * 商品icon
     */
    private String productIcon;

    /**
     * 商品状态，0上架1下架
     */
    private Integer productStatus = ProductStatus.UP.getCode();

    /**
     * 类目编号
     */
    private Integer categoryType;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 修改时间
     */
    private Date updateTime;

    @JsonIgnore
    public ProductStatus getStatus() {
        return EnumUtil.getByCode(this.productStatus, ProductStatus.class);
    }

}
